<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<form:form commandName="model" cssClass="validate"
	action="individuation/category/save">
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">父级：</td>
				<td class="td2"><form:input path="parentId" cssClass="hidden" />
					<isperp:treeSelector id="selectParentindividuationCategory"
						url="individuation/category/getTree" valueControlId="parentId"
						displayValue="${parentName}" displayValueCssClass="required"></isperp:treeSelector>
				</td>
			</tr>

			<tr>
				<td class="td1">名称：</td>
				<td class="td2"><form:input path="name" cssClass="required" />
				</td>
			</tr>

			<tr id="tr1">
				<td class="td1">是否主表单：</td>
				<td class="td2"><form:radiobutton label="是" value="1"
						path="areMainForm" /> <form:radiobutton label="否" value="0"
						path="areMainForm" /></td>
			</tr>

			<tr id="tr2">
				<td class="td1">IDKey：</td>
				<td class="td2"><form:input path="id" cssClass="required"
						placeholder="不能重复，表单唯一标示" /></td>
			</tr>

			<tr>
				<td class="td1">是否展开：</td>
				<td class="td2"><form:checkbox path="open" />
				</td>
			</tr>
			<tr>
				<td class="td1">排序：</td>
				<td class="td2"><form:input path="orderNum" cssClass="number" />
				</td>
			</tr>
		</tbody>
	</table>

</form:form>



<isperp:buttonList>
	<button class="submit" onclick="check();">
		<span class="icon icon-save"></span>提交
	</button>
</isperp:buttonList>
<script type="text/javascript">
	function check() {
		//一个流程表单后只能有一个主表单
		var parentId = '${model.parentId}';
		var id = $("#id").val();
		var areMainForm = $('input[name="areMainForm"]:checked ').val();
		if (parentId != "") {
			$.ajax({
				async : false,
				url : 'individuation/category/getIfExistsMainFormByParentId?parentId=' + parentId + '&id=' + id,
				success : function(data) {
					if (data.success && areMainForm == "1") {
						isperp.alert("一个流程表单下只能设置一个主表单");
						return false;
					} else {
						isperp.submitForm();
						return false;
					}

				}
			});
			return false;

		} else {
			isperp.submitForm();
			return false;
		}
	}

	$(function() {
		var parentId = '${model.parentId}';
		if ($("#name").val() == "" && parentId != "") {
			document.getElementById("areMainForm1").checked = true;
			$("#id").val("");
		}

		if (parentId == "") {
			$("#tr1,#tr2").hide();
		}
	});
</script>
